//
//  BaseViewController.m
//  PageTitleContent
//
//  Created by 好米有易 on 2017/9/14.
//  Copyright © 2017年 好米有易. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

/** webView */
@property (nonatomic, strong) UIWebView *webView;

@end

@implementation BaseViewController

- (void)loadView {
    [super loadView];
    
    self.view = self.webView;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self loadString:@"ios"];
}

// 让浏览器加载指定的字符串,使用m.baidu.com进行搜索
- (void)loadString:(NSString *)str  {
    // 1. URL 定位资源,需要资源的地址
    NSString *urlStr = str;
    if (![str hasPrefix:@"https://"]) {
        urlStr = [NSString stringWithFormat:@"https://m.baidu.com/s?word=%@", str];
    }
    
    NSURL *url = [NSURL URLWithString:urlStr];
    
    // 2. 把URL告诉给服务器,请求,从m.baidu.com请求数据
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    // 3. 发送请求给服务器
    [self.webView loadRequest:request];
}


#pragma mark - lazy -
- (UIWebView *)webView {
    
    if (_webView == nil) {
        _webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
        _webView.scalesPageToFit = YES;//自动对页面进行缩放以适应屏幕
        _webView.dataDetectorTypes = UIDataDetectorTypePhoneNumber;
        //_webView.detectsPhoneNumbers = YES;//自动检测网页上的电话号码，单击可以拨打
    }
    return _webView;
}



@end
